﻿using MugenInjection.Bindings;
using MugenInjection.Interface;

namespace MugenInjection.Scope
{
    /// <summary>
    ///     Represents the default <see cref="IScopeLifecycleContext" />.
    /// </summary>
    internal sealed class DefaultScopeLifecycleContext : IScopeLifecycleContext
    {
        #region Fields

        private readonly BindingBase _bindingBase;

        #endregion

        #region Constructor

        /// <summary>
        ///     Initializes a new instance of the <see cref="DefaultScopeLifecycleContext" /> class.
        /// </summary>
        public DefaultScopeLifecycleContext(BindingBase bindingBase)
        {
            _bindingBase = bindingBase;
        }

        #endregion

        #region Implementation of IScopeLifecycleContext

        /// <summary>
        /// Gets the <see cref="IBinding"/>.
        /// </summary>
        public IBinding Binding
        {
            get { return _bindingBase; }
        }

        /// <summary>
        ///     Gets the current <see cref="IBindingContext" />.
        /// </summary>
        public IBindingContext BindingContext { get; internal set; }

        /// <summary>
        ///     Resolves instance for the specified <see cref="IBindingContext" />.
        /// </summary>
        /// <returns>An instance of the service.</returns>
        public object ResolveCurrentService()
        {
            return _bindingBase.ResolveServiceInternal(BindingContext);
        }

        #endregion
    }
}